package com.example.demo.service;

import com.example.demo.dao.UserMapper;
import com.example.demo.exception.ApplicationException;
import com.example.demo.model.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lishuo
 * Date: 2023-11-27
 * Time: 9:53
 */
@Slf4j
@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;

    public void reg(UserInfo userInfo) {
        int result = userMapper.reg(userInfo);
        if (result != 1) {
            log.error("注册失败：userName = "+userInfo.getUsername());
            throw new ApplicationException("注册失败！");
        }
    }

    public UserInfo getUserByName(String username) {
        return userMapper.getUserByName(username);
    }


}
